package day04_Array;
//选择排序
public class 选择排序 {
    public static void main(String[] args) {
        int [] arr={5,9,3,6,4,1,8,7,2};
        for (int i = 0; i <arr.length-1 ; i++) {
            int maxIndex=0;
            for (int j = 0; j <arr.length-i ; j++) {
                if (arr[j]>arr[maxIndex]){
                    maxIndex=j;
                }
            }
            int x=arr[maxIndex];
            arr[maxIndex]=arr[arr.length-i-1];
            arr[arr.length-i-1]=x;
        }
        for (int i = 0; i <arr.length ; i++) {
            System.out.println(arr[i]);
        }
    }
}
